<template>
    <div>
        <h1>注册界面</h1>
        <table class="table table-bordered">
            <tr>
                <td>用户名</td>
                <td><input type="text" v-model="info.UL_Name" placeholder="请输入用户名"/></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="info.UL_Pwd" placeholder="请输入密码"/></td>
            </tr>
            <tr>
                <td colspan="2"><input value="注册" type="button" @click="SaveData"/></td>
            </tr>
        </table>
    </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';

const info=ref({
    UL_Name:'',
    UL_Pwd:''
})
import axios from 'axios';
import { useRouter } from 'vue-router';
const route=useRouter();


const SaveData = () => {
    if(info.value.UL_Name=='' || info.value.UL_Pwd==''){
        alert("用户名或密码不能为空")
        return;
    }

    if(info.value.UL_Pwd.length<6)
    {
        alert("密码长度不能小于6位")
        return;
    }
    if(info.value.UL_Pwd.length>16)
    {
        alert("密码长度不能大于16位")
        return;
    }

    alert(info.value.UL_Name+"," +info.value.UL_Pwd)
    axios({
        method: 'post',
        url: 'http://localhost:57969/api/User/UserRegister',
        data: info.value
    })
    .then(function (res) {
        if(res.data>0)
        {
            alert("注册成功");
            route.push('/Login');
        }
        else if(res.data==-1)
        {
            alert("用户名已存在");
            return;
        }

        else
        {
            alert("注册失败");
        }
    })



}
</script>